﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.Data;
namespace HA.ModFlow.Controls.Windows.DataOperation
{
    /// <summary>
    /// winVariogramEditor.xaml 的交互逻辑
    /// </summary>
    public partial class winVariogramEditor : Window
    {
        public winVariogramEditor(Project proj)
        {
            InitializeComponent();
            this._proj = proj;
            //this._proj.InterpolationOption2D.KrigingOption.ModelVariogram = new HAMath.ModelVariogram(HAMath.ModelType.Spherical, 10, 20, 30);
            //this.DataContext = this._proj.InterpolationOption2D.KrigingOption.ModelVariogram;
        }

        Project _proj;

        public Project Proj
        {
            get { return _proj; }       
        }

        private List<HAMath.ModelVariogram> _arryVariogram = new List<HAMath.ModelVariogram>();

        public List<HAMath.ModelVariogram> ArryVariogram
        {
            get { return _arryVariogram; }
            set { _arryVariogram = value; }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.lstNested.ItemsSource = ArryVariogram;
            if (this.lstNested.Items.Count > 0)
            {
                this .lstNested .SelectedIndex=0;
            }
        }

        private void btnAddNested_Click(object sender, RoutedEventArgs e)
        {
            this.ArryVariogram.Add(new HAMath.ModelVariogram(HAMath.ModelType.Spherical, 11, 22, 30));
            this.lstNested.ItemsSource = ArryVariogram;
            this.lstNested.Items.Refresh();
        }

        private void lstNested_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            System.ComponentModel.ICollectionView view = CollectionViewSource.GetDefaultView(ArryVariogram);
            this.DataContext = (HAMath.ModelVariogram)view.CurrentItem;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

      

       
    }

    public class ConvertToModelType : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            HAMath.ModelType type = (HAMath.ModelType)value;
            int index = 0;
            switch (type)
            {
                case HAMath.ModelType.Spherical:
                    index = 0;
                    break;
                case HAMath.ModelType.Exponential:
                    index = 1;
                    break;
                //case HAMath.ModelType.Gaussian:
                //    index = 2;
                //    break;
                //case HAMath.ModelType.Power:
                //    index = 3;
                //    break;
            }
            return index;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            HAMath.ModelType type =HAMath.ModelType.Spherical;
            int index =(int )value;
            switch (index)
            {
                case 0:
                    type = HAMath.ModelType.Spherical;
                    break;
                case 1:
                    type = HAMath.ModelType.Exponential;
                    break;
                //case 2:
                //    type = HAMath.ModelType.Gaussian;
                //    break;
                //case 3:
                //    type = HAMath.ModelType.Power;
                //    break;
            }
            return type;
        }
    }

}
